import { baseUrl } from './config'

// 所有榜单内容摘要
export function topList() {

  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/toplist/detail`,
      method: 'GET',
      data: {},
      success: res => {
        let result = res.data.list;
        result.length = 4;
        resolve(result)
      },
      fail: () => {
        reject()
      },
      complete: () => {}
    })
  })
}

// 获取歌单详情
export function playListDetail(id) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/playlist/detail?id=${id}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 获取歌曲详情
export function songDetail(ids) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/song/detail?ids=${ids}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 获取相似音乐 
export function songSimi(id) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/simi/song?id=${id}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 歌曲评论  
export function songComment(id) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/comment/music?id=${id}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 获取歌词 lyric 
export function songLyric(id) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/lyric?id=${id}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 获取客户端歌曲下载 url 
export function songUrl(id) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/song/url?id=${id}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 搜索
export function searchKeyWords(keywords) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/search?keywords=${keywords}`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 热搜列表(详细)
export function searchHotDetail() {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/search/hot/detail`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}

// 搜索建议
export function searchSuggest(keywords) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}/search/suggest?keywords=${keywords}&type=mobile`,
      method: 'GET',
      success: res => {
        let result = res.data
        resolve(result)
      },
      fail: () => {
        reject()
      }
    })
  })
}
